﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace VietKinsNutrition.Data
{
    public class ClsTblDm_DotuoiDAL
    {
        ClsBindingBLL ClsBin = new ClsBindingBLL();
        //ClsConnection ClsCnn = new ClsConnection();
        public DataTable SelectAll()
        {
            string NamePrc = QueryString.SP_DOTUOI_GET;
            string NameTable = "TblDm_Dotuoi";
            DataTable NewTable = new DataTable();
            NewTable.TableName = NameTable;

            DataColumn Columm = new DataColumn();
            Columm.ColumnName = Columm.Caption = "STT";
            Columm.DataType = System.Type.GetType("System.Int32");
            Columm.AllowDBNull = false;
            Columm.AutoIncrement = true;
            Columm.AutoIncrementSeed = Columm.AutoIncrementStep = 1;
            NewTable.Columns.Add(Columm);
            OleDbCommand Cmm = new OleDbCommand();
            OleDbDataAdapter Dap;
            Cmm.Connection = ClsConnection.OleDBConnect();
            Cmm.CommandText = NamePrc;
            ////Cmm.CommandType = CommandType.StoredProcedure;
            try
            {
                if (Cmm.Connection.State != ConnectionState.Open) Cmm.Connection.Open(); Cmm.ExecuteNonQuery();
            }
            catch (Exception Ex)
            {
            }
            finally
            {
                Cmm.Connection.Close();
            }
            Dap = new OleDbDataAdapter(Cmm);
            Dap.Fill(NewTable);
            return NewTable;
        }
        public void Insert(float Tuoicanduoi, float Tuoicantren, string Tendotuoi)
        {
            string NamePrc = QueryString.SP_DOTUOI_ADD.Replace("@Tuoicanduoi", Tuoicanduoi.ToString()).Replace("@Tuoicantren", Tuoicantren.ToString()).Replace("@Tendotuoi", Tendotuoi);
            OleDbCommand Cmm = new OleDbCommand();
            Cmm.Parameters.Add(new OleDbParameter("@Tuoicanduoi", Tuoicanduoi));
            Cmm.Parameters.Add(new OleDbParameter("@Tuoicantren", Tuoicantren));
            Cmm.Parameters.Add(new OleDbParameter("@Tendotuoi", Tendotuoi));
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
        }

        public DataSet SelectById(int Id)
        {
            string NamePrc = QueryString.SP_DOTUOI_GETBYID.Replace("@Id", Id.ToString());
            string NameTable = "TblDm_Dotuoi";
            DataSet Dset = new DataSet();
            DataTable NewTable = new DataTable();
            NewTable.TableName = NameTable;
            Dset.Tables.Add(NewTable);
            OleDbCommand Cmm = new OleDbCommand();
            Cmm.Parameters.Add(new OleDbParameter("@Id", Id));

            Cmm.Connection = ClsConnection.OleDBConnect();
            Cmm.CommandText = NamePrc;
            //Cmm.CommandType = CommandType.StoredProcedure;
            try
            {
                if (Cmm.Connection.State != ConnectionState.Open) Cmm.Connection.Open(); Cmm.ExecuteNonQuery();
            }
            catch (Exception Ex)
            {
            }
            finally
            {
                Cmm.Connection.Close();
            }
            OleDbDataAdapter Dap;
            Dap = new OleDbDataAdapter(Cmm);
            Dap.Fill(Dset.Tables[NameTable]);

            return Dset;
        }

        public void Edit(int Id, float Tuoicanduoi, float Tuoicantren, string Tendotuoi)
        {
            string NamePrc = QueryString.SP_DOTUOI_UPDATE.Replace("@Id", Id.ToString()).Replace("@Tuoicanduoi", Tuoicanduoi.ToString()).Replace("@Tuoicantren", Tuoicantren.ToString()).Replace("@Tendotuoi", Tendotuoi);
            OleDbCommand Cmm = new OleDbCommand();
            Cmm.Parameters.Add(new OleDbParameter("@Id", Id));
            Cmm.Parameters.Add(new OleDbParameter("@Tuoicanduoi", Tuoicanduoi));
            Cmm.Parameters.Add(new OleDbParameter("@Tuoicantren", Tuoicantren));
            Cmm.Parameters.Add(new OleDbParameter("@Tendotuoi", Tendotuoi));
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
        }
        public void Del(int Id)
        {
            string NamePrc = QueryString.SP_DOTUOI_DEL;
            OleDbCommand Cmm = new OleDbCommand();
            Cmm.Parameters.Add(new OleDbParameter("@Id", Id));
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
        }
        public DataSet SelectByName(string Tendotuoi)
        {
            string NamePrc = QueryString.SP_DOTUOI_GETBYNAME.Replace("@Tendotuoi", Tendotuoi);
            string NameTable = "TblDm_Dotuoi";
            DataSet Dset = new DataSet();
            DataTable NewTable = new DataTable();
            NewTable.TableName = NameTable;

            DataColumn Columm = new DataColumn();
            Columm.ColumnName = Columm.Caption = "STT";
            Columm.DataType = System.Type.GetType("System.Int32");
            Columm.AllowDBNull = false;
            Columm.AutoIncrement = true;
            Columm.AutoIncrementSeed = Columm.AutoIncrementStep = 1;
            NewTable.Columns.Add(Columm);
            Dset.Tables.Add(NewTable);
            OleDbCommand Cmm = new OleDbCommand();
            Cmm.Parameters.Add(new OleDbParameter("@Tendotuoi", Tendotuoi));

            Cmm.Connection = ClsConnection.OleDBConnect();
            Cmm.CommandText = NamePrc;
            //Cmm.CommandType = CommandType.StoredProcedure;
            try
            {
                if (Cmm.Connection.State != ConnectionState.Open) Cmm.Connection.Open(); Cmm.ExecuteNonQuery();
            }
            catch (Exception Ex)
            {
            }
            finally
            {
                Cmm.Connection.Close();
            }
            OleDbDataAdapter Dap;
            Dap = new OleDbDataAdapter(Cmm);
            Dap.Fill(Dset.Tables[NameTable]);

            return Dset;
        }
    }
}
